package edu.java.texbooks.scjp.threads.test01;

public class TestThread {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// testCounterThread();
		// testDownCounter();
		// testInterruptMethodOfThread();
		testPriorityThread();

	}

	public static void testCounterThread() {
		CounterThread ct = new CounterThread();
		ct.start();

		for (int i = 0; i < 5; i++) {
			System.out.println("Calling thread: " + i);
		}

		System.out
				.println("Execute run() method of CounterThread in current thread.");
		ct.run();
	}

	public static void testDownCounter() {
		DownCounter dc = new DownCounter();
		Thread t = new Thread(dc);
		t.start();

		for (int i = 0; i < 5; i++) {
			System.out.println("Calling thread: " + i);
		}

		System.out
				.println("Execute run() method of DownCounter in current thread.");
		t.run();
	}

	public static void testInterruptMethodOfThread() {
		DownCounter dc = new DownCounter();
		Thread t = new Thread(dc);
		t.start();
		t.interrupt();
		System.out
				.println("Interrupt thread which execute run() method of DownCounter object");
		// t.interrupt();

		for (int i = 0; i < 5; i++) {
			System.out.println("Calling thread: " + i);
		}

		System.out
				.println("Execute run() method of DownCounter in current thread.");
		t.run();
	}

	public static void testPriorityThread() {
		// // MyThread priority
		// System.out.println("-------- MyThread priority -----------");
		// MyThread mt = new MyThread();
		// System.out.println("myThread priority: " + mt.getPriority());
		//
		// int oldPriority = mt.getPriority();
		// int newPriority = Math.min(oldPriority + 1, Thread.MAX_PRIORITY);
		//
		// mt.setPriority(newPriority);
		// System.out.println("Increment myThread priority: " +
		// mt.getPriority());
		//
		// // MySpecialThread
		// System.out.println("\n------- MySpecialThread ------------");
		// MySpecialThread mst = new MySpecialThread();
		// System.out.println("MySpecialThread priority: " + mst.getPriority());
		//				
		// // Thread Priority Constants
		// System.out.println("\n------- Thread Priority Constants ------------");
		// System.out.println("Thread MIN_PRIORITY: " + Thread.MIN_PRIORITY);
		// System.out.println("Thread NORM_PRIORITY: " + Thread.NORM_PRIORITY);
		// System.out.println("Thread MAX_PRIORITY: " + Thread.MAX_PRIORITY);

		// test run() methods
		// MyThread mt2 = new MyThread();
		// MySpecialThread mst2 = new MySpecialThread();
		// mt2.run();
		// System.out.println();
		// mst2.run();
		
		// test priorities
		MyThread mt3= new MyThread(Thread.MIN_PRIORITY);
		MySpecialThread mst3= new MySpecialThread(Thread.MAX_PRIORITY);
		
		System.out.println("start");
		mt3.start();
		System.out.println();
		mst3.start();
		System.out.println();
		System.out.println("finish");
		
		

	}
}
